package com.yqd.lesson.actor.two
import java.util.concurrent.TimeoutException

import scala.concurrent.duration._
import akka.actor.{Actor, ActorLogging, Props, ReceiveTimeout}

import scala.concurrent.duration.Duration


object Sender{
  def props : Props = Props[Sender]
}

class Sender extends Actor with ActorLogging{
  context.setReceiveTimeout(5.second)
  override def receive: Receive = {
    case msg:String =>{
      0/0
    }
    case msg:Int =>{
      println(msg)
    }
    case ReceiveTimeout =>
     context.setReceiveTimeout(Duration.Undefined)
  }

  override def preStart(): Unit = {
    super.preStart()
    log.info("-------preStart------")
  }

  override def unhandled(message: Any): Unit = {
    super.unhandled(message)
    log.info("-------unhandled------")
  }

  override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
    super.preRestart(reason, message)
    log.info("-------preRestart------")
  }

  override def postRestart(reason: Throwable): Unit = {
    super.postRestart(reason)
    log.info("-------postRestart------")
  }

  override def postStop(): Unit = {
    super.postStop()
    log.info("-------postStop------")
  }




}
